package com.market.coupon.server.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.market.common.log.annotation.Log;
import com.market.common.log.enums.BusinessType;
import com.market.common.security.annotation.RequiresPermissions;
import com.market.coupon.common.domain.TUserRepertory;
import com.market.coupon.server.service.ITUserRepertoryService;
import com.market.common.core.web.controller.BaseController;
import com.market.common.core.utils.poi.ExcelUtil;
import com.market.common.core.web.page.TableDataInfo;
import com.market.common.core.domain.Result;

/**
 * 用户优惠券Controller
 *
 * @author market
 * @date 2024-03-05
 */
@RestController
@RequestMapping("/repertory")
public class TUserRepertoryController extends BaseController
{
    @Autowired
    private ITUserRepertoryService tUserRepertoryService;

    /**
     * 查询用户优惠券列表
     */
    @RequiresPermissions("repertory:repertory:list")
    @GetMapping("/list")
    public Result<TableDataInfo> list(TUserRepertory tUserRepertory)
    {
        startPage();
        List<TUserRepertory> list = tUserRepertoryService.selectTUserRepertoryList(tUserRepertory);
        return getDataTable(list);
    }
    /*
    *
    * */

    /**
     * 导出用户优惠券列表
     */
    @RequiresPermissions("repertory:repertory:export")
    @Log(title = "用户优惠券", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TUserRepertory tUserRepertory)
    {
        List<TUserRepertory> list = tUserRepertoryService.selectTUserRepertoryList(tUserRepertory);
        ExcelUtil<TUserRepertory> util = new ExcelUtil<TUserRepertory>(TUserRepertory.class);
        util.exportExcel(response, list, "用户优惠券数据");
    }

    /**
     * 获取用户优惠券详细信息
     */
    @RequiresPermissions("repertory:repertory:query")
    @GetMapping(value = "/{userRepertoryId}")
    public Result getInfo(@PathVariable("userRepertoryId") Long userRepertoryId)
    {
        return success(tUserRepertoryService.selectTUserRepertoryByUserRepertoryId(userRepertoryId));
    }

    /**
     * 新增用户优惠券
     */
    @RequiresPermissions("repertory:repertory:add")
    @Log(title = "用户优惠券", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody TUserRepertory tUserRepertory)
    {
        return toAjax(tUserRepertoryService.insertTUserRepertory(tUserRepertory));
    }

    /**
     * 修改用户优惠券
     */
    @RequiresPermissions("repertory:repertory:edit")
    @Log(title = "用户优惠券", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody TUserRepertory tUserRepertory)
    {
        return toAjax(tUserRepertoryService.updateTUserRepertory(tUserRepertory));
    }

    /**
     * 删除用户优惠券
     */
    @RequiresPermissions("repertory:repertory:remove")
    @Log(title = "用户优惠券", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userRepertoryIds}")
    public Result remove(@PathVariable Long[] userRepertoryIds)
    {
        return toAjax(tUserRepertoryService.deleteTUserRepertoryByUserRepertoryIds(userRepertoryIds));
    }
    /**
     * 查询优惠券
     */
    @PostMapping("/queryType")
    public Result queryType()
    {
        return success(tUserRepertoryService.queryType());
    }
}
